package com.aaa.mks.controller;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.mks.entity.Shop;
import com.aaa.mks.service.ShopService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Shop)表控制层
 *
 * @author makejava
 * @since 2020-11-26 19:38:33
 */
@RestController
@RequestMapping("shop")
public class ShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Shop selectOne(Integer id) {
        return this.shopService.queryById(id);
    }

    /**
     * 查询所有店铺
     * @param shop
     * @return
     */
    @GetMapping("queryAll")
    public Result queryAll(Integer pageNo, Integer pageSize, Shop shop){
        return this.shopService.queryAll(pageNo, pageSize, shop);
    }

    @DeleteMapping("delete")
    public Result delete(Integer shopid){
        if(this.shopService.deleteById(shopid)){
            return new Result(ReturnCode.SUCCESSS.getCode(),ReturnCode.SUCCESSS.getMsg(),this.shopService.deleteById(shopid));
        }else{
            return new Result(ReturnCode.FAIL.getCode(),ReturnCode.FAIL.getMsg(),this.shopService.deleteById(shopid));
        }
    }

    /**
     * 更新店铺
     * @param shop
     * @return
     */
    @PutMapping("update")
    public Shop update(@RequestBody Shop shop){
        return this.shopService.update(shop);
    }

    @PostMapping("insert")
    public Shop insert(@RequestBody Shop shop){
        return this.shopService.insert(shop);
    }

}